﻿using System;
using System.Windows.Input;

namespace Jerry.DroidBuilder.Common
{
    public class DelegateCommand<PAYLOAD> : ICommand
    {
        private Action<PAYLOAD> _action;

        public DelegateCommand(Action<PAYLOAD> action)
        {
            _action = action;
        }

        public event EventHandler CanExecuteChanged;

        public bool CanExecute(object parameter)
        {
            return true;
        }

        public void Execute(object parameter)
        {
            if (null != _action)
            {
                if (null == parameter)
                {
                    parameter = default(PAYLOAD);
                }

                _action((PAYLOAD)parameter);
            }
        }
    }
}
